package com.chengyu.stock.controller;

import com.chengyu.stock.pojo.domain.*;
import com.chengyu.stock.service.StockService;
import com.chengyu.stock.vo.resp.PageResult;
import com.chengyu.stock.vo.resp.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import javax.swing.*;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/quot")
public class StockController {

    @Autowired
    private StockService stockService;

    //获取国内大盘的最新交易数据
    @GetMapping("/index/all")
    public R<List<InnerMarketDomain>> getNewestInnerMarketInfos() {
        return stockService.getNewestInnerMarketInfos();
    }

    //获取板块交易数据
    @GetMapping("/sector/all")
    public R<List<StockBlockDomain>> getNewestSectorMarketInfos() {
        return stockService.getNewestSectorMarketInfos();
    }

    //获取涨幅榜更多数据
    @GetMapping("/stock/all")
    public R<PageResult<StockUpdownDomain>> getNewestStockPageInfo(@RequestParam(name = "page", required = false, defaultValue = "1") Integer page,
                                                                   @RequestParam(name = "pageSize", required = false, defaultValue = "20") Integer pageSize) {
        return stockService.getNewestStockPageInfo(page, pageSize);
    }

    //获取涨幅榜数据
    @GetMapping("/stock/increase")
    public R<List<StockUpdownDomain>> getNewestStockIncreaseInfo() {
        return stockService.getNewestStockIncreaseInfo();
    }

    //获取涨跌停数据
    @GetMapping("/stock/updown/count")
    public R<Map> getStockUpdownCount() {
        return stockService.getStockUpdownCount();
    }

    //将指定页的股票数据导出到excel表下
    @GetMapping("/stock/export")
    public void stockExport(HttpServletResponse response, Integer page, Integer pageSize) {
        stockService.stockExport(response, page, pageSize);
    }

    //昨日今日交易量对比(成交量为沪市和深市成交量之和)
    @ApiOperation("昨日今日交易量对比(成交量为沪市和深市成交量之和)")
    @GetMapping("/stock/tradevol")
    public R<Map<String, List>> getStockMarketTradeCompare() {
        return stockService.getStockMarketTradeCompare();

    }

    //个股分时涨跌幅度统计功能
    @GetMapping("/stock/updown")
    public R<Map<String, Object>> getLastDate4Stock() {
        return stockService.getLastDate4Stock();
    }

    //股票分时K线图
    @GetMapping("/stock/screen/time-sharing")
    public R<List<Stock4MinuteDomain>> getStockScreenTimeSharing(String code) {
        return stockService.getStockScreenTimeSharing(code);
    }

    //股票日K线图
    @GetMapping("/stock/screen/dkline")
    public R<List<Stock4EvrDayDomain>> getStockScreenEvrDaySharing(String code) {
        return stockService.getStockScreenEvrDaySharing(code);
    }

    //获取外盘数据StockOuterMarketDomain
    @GetMapping("/external/index")
    public R<List<StockOuterMarketDomain>> getStockOuterMarketInfos(){
        return stockService.getStockOuterMarketInfos();
    }

    //股票Code联想推荐功能
    @GetMapping("/stock/search")
    public R<List<Map>> searchStock(String searchStr){
        return stockService.searchStock(searchStr);
    }

    //个股描述功能
    @GetMapping("/stock/describe")
    public R<StockBusinessDomain> getStockDescribe(String code){
        return stockService.getStockDescribe(code);
    }

    //个股周K线功能接口
    @GetMapping("/stock/screen/weekkline")
    public R<List<Stock4EvrWeekDomain>> getWeekKLinData(String code){
        return stockService.getWeekKLinData(code);
    }

    //个股最新分时行情数据接口
    @GetMapping("/stock/screen/second/detail")
    public R<StockLatestInfoDomain> getStockSecondDetail(String code){
       return null;
    }

}
